package com.shop.loan.model;

import com.shop.loan.proxy.LoanOrderPayLogProxy;
import com.shop.loan.util.LoanOrderUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "s_loan_order_pay_log")
@Erupt(
        name = "订单还款记录",
        orderBy = "id desc",
        power = @Power(add = false, edit = false, delete = false, viewDetails = false),
        dataProxy = LoanOrderPayLogProxy.class,
        filter = @Filter("LoanOrderPayLog.isDelete = false"),
        rowOperation = {
//                @RowOperation(
//                        title = "删除记录",
//                        icon = "fa fa-trash-o text-red",
//                        mode = RowOperation.Mode.SINGLE,
//                        eruptClass = LoanOrderPayLogDelVo.class,
//                        operationHandler = LoanOrderPayLogDelHandler.class
//                )
        }
)
@SQLDelete(sql = "update s_loan_order_pay_log set is_delete = true, delete_time = now() where id = ?")
@Getter
@Setter
public class LoanOrderPayLog extends BaseModel {


    @Transient
    @EruptField(
            edit = @Edit(
                    title = "手机号码",
                    show = false,
                    search = @Search
            )
    )
    private String userPhone;

    @Transient
    @EruptField(
            edit = @Edit(
                    title = "姓名",
                    show = false,
                    search = @Search
            )

    )
    private String userName;


    @Transient
    @EruptField(
            views = @View(title = "用户", type = ViewType.SAFE_TEXT, width = LoanOrderUtil.orderListByUserWidth)
    )
    private String userInfo;


    @EruptField(
            views = @View(title = "订单id", width = "100px"),
            edit = @Edit(title = "订单id", notNull = true)
    )
    @Column(name = "order_id")
    private Long orderId;

    @Column(name = "bill_id")
    private Long billId;

    @EruptField(
            views = @View(title = "用户id", width = "100px", show = false),
            edit = @Edit(title = "用户id", notNull = true)
    )
    @Column(name = "user_id")
    private Long userId;

    @EruptField(
            views = @View(title = "期数", width = "100px"),
            edit = @Edit(title = "期数", notNull = true)
    )
    private Integer period;

    @EruptField(
            views = @View(title = "金额", width = "150px"),
            edit = @Edit(title = "金额", notNull = true)
    )
    private BigDecimal money;

    @EruptField(
            views = @View(title = "线上付款"),
            edit = @Edit(
                    title = "线上付款",
                    search = @Search,
                    type = EditType.BOOLEAN,
                    boolType = @BoolType(
                            trueText = "是",
                            falseText = "否"
                    )
            )
    )
    private Boolean online;

    @EruptField(
            views = @View(title = "还款方式"),
            edit = @Edit(
                    title = "还款方式",
                    type = EditType.CHOICE,
                    notNull = true,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "线下支付宝", value = "1"),
                                    @VL(label = "线下微信", value = "2"),
                                    @VL(label = "企业微信", value = "3"),
                                    @VL(label = "宝付", value = "4"),
                                    @VL(label = "统统付", value = "5"),
                                    @VL(label = "其他", value = "9"),
                            }
                    ))
    )
    private Integer paymentType;


    @EruptField(
            views = @View(title = "还款类型"),
            edit = @Edit(
                    title = "还款类型",
                    type = EditType.CHOICE,
                    notNull = true,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "本息", value = "1"),
                                    @VL(label = "担保费", value = "2"),
                            }
                    ))
    )
    private Integer payType;


    @EruptField(
            views = @View(title = "支付订单Id"),
            edit = @Edit(
                    title = "支付订单Id",
                    search = @Search
            )
    )
    private String payOrderId;


    @EruptField(
            views = @View(title = "备注"),
            edit = @Edit(
                    title = "备注"
            )
    )
    private String remark;


    @EruptField(
            views = @View(title = "还款时间"),
            edit = @Edit(title = "还款时间",
                    readonly = @Readonly,
                    search = @Search(vague = true),
                    dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private Date createTime;


    private Boolean isDelete = false;

    private Date deleteTime;

}
